from core.entities import Chemical, Hazard, PhysicalState
from services.graph_service import Neo4jGraphService
from utils.config_loader import Settings

def init_sample_data():
    config = Settings.get_settings()
    service = Neo4jGraphService(
        uri=config.neo4j_uri,
        auth=(config.neo4j_user, config.neo4j_password)
    )

    # 示例化学品
    sulfuric_acid = Chemical(
        id="7664-93-9",
        name="硫酸",
        en_name="Sulfuric Acid",
        cas="7664-93-9",
        un="UN1830",
        molecular_formula="H2SO4",
        physical_state=PhysicalState.LIQUID,
        aliases=["电池酸"]
    )

    # 危害特性
    corrosion = Hazard(
        name="腐蚀性",
        code="GHS05",
        severity=3,
        icon="corrosion.png"
    )

    # 写入图数据库
    try:
        service.create_chemical(sulfuric_acid)
        service.add_hazard(sulfuric_acid.id, corrosion)
        print("示例数据初始化成功！")
    finally:
        service.close()

if __name__ == "__main__":
    init_sample_data()